package org.posta.web.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.HTML;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.ButtonConfig;
import com.gwtext.client.widgets.LayoutDialog;
import com.gwtext.client.widgets.LayoutDialogConfig;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.layout.BorderLayout;
import com.gwtext.client.widgets.layout.ContentPanel;
import com.gwtext.client.widgets.layout.LayoutRegionConfig;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Posta implements EntryPoint
{
    
    /**
     * This is the entry point method.
     */
    public void onModuleLoad()
    {
        final LayoutDialog dialog = new LayoutDialog(new LayoutDialogConfig() {
            {
                setTitle("Basic Dialog");
                setModal(true);
                setWidth(500);
                setHeight(300);
                setShadow(true);
                setMinHeight(300);
                setMinHeight(300);
            }
        }, new LayoutRegionConfig());
        
        // first way to add button
        Button saveBtn = dialog.addButton("Submit");
        saveBtn.disable();
        
        // another way to add button
        dialog.addButton(new Button("Cancel", new ButtonConfig() {
            {
                setText("Cancel");
                setButtonListener(new ButtonListenerAdapter() {
                    public void onClick(Button button, EventObject e)
                    {
                        dialog.hide();
                    }
                });
            }
        }));
        
        // add content to the center region
        BorderLayout layout = dialog.getLayout();
        ContentPanel contentPanel = new ContentPanel();
        contentPanel.add(new HTML("<h1>Hello World!!</h1>"));
        layout.add(contentPanel);
        
        Button button = new Button("Hello World");
        button.addButtonListener(new ButtonListenerAdapter() {
            public void onClick(Button button, EventObject e)
            {
                dialog.show(button.getEl());
                /*
                PopupPanel messagePanel = new PopupPanel(true);
                messagePanel.setPopupPosition(500, 300);
                messagePanel.setWidget(new HTML(getMessageHtml( "Title", "message")));
                messagePanel.setWidth("300px");
                messagePanel.show();
                */
            }
        });
    }
    
    private static native String getMessageHtml(String title, String message) /*-{
    return ['<div class="msg">',
            '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
            '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', title, '</h3>', message, '</div></div></div>',
            '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
            '</div>'].join('');
    }-*/;
    
}
